using Services;
using UnityEngine;

[RequireComponent(typeof(PointTrigger_Player))]
public class CheckPoint : MonoBehaviour
{
    private SaveManager saveManager;
    private PointTrigger_Player trigger;
    private Player player;

    protected virtual void Awake()
    {
        player = ServiceLocator.Get<ActionController>().player;
        saveManager = ServiceLocator.Get<SaveManager>();
        trigger = GetComponent<PointTrigger_Player>();
        trigger.OnTriggerStay += MyOnTriggerStay;
    }

    private void MyOnTriggerStay(Player player)
    {
        if (Input.GetKeyDown(KeyCode.F))
            Save();
    }

    protected void Save()
    {
        player.HealthPoint = player.data.maxHP;
        player.EnergyPoint = player.data.maxEP;
        player.StatusManager.RemoveAllStatus();
        saveManager.Save();
    }
}
